/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mighty.team.homemediacenterdescriptor.json;

import com.mighty.team.homemediacenterdescriptor.init.OnSupport;
import com.mighty.team.homemediacenterdescriptor.model.Movie;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;

/**
 *
 * @author TSokolowski
 */
public class JsonParser {
private final static Logger LOGGER = Logger.getLogger(JsonParser.class .getName());
    public JSONObject readJsonFromUrl(String address) throws IOException, JSONException {
        String jsonString = "";
        JSONObject jsonMessage = null;
        try {
            URL url = new URL(address.toString());
            BufferedReader in = new BufferedReader(new InputStreamReader(
                    url.openStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null) {
                jsonString = inputLine;
            }         
            in.close();            
            jsonMessage = (JSONObject) JSONSerializer.toJSON(jsonString); 
            
        } catch (IOException e) {
           LOGGER.log(Level.ALL,"Exception cought: " + e);
        }
        return jsonMessage;
    }     
    
}
